home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga CD-ROM Collection
/
Amiga CD-ROM Collection - Auge 4000 and Cactus and Demo Util.iso
/
auge4000
/
46
/
lib
/
amiga
/
divu.a
< prev
next >
Wrap
Text File
|
1990-06-20
|
1KB
|
67 lines
section text,code
xdef __divu
__divu:
move.l D2,-(sp)
cmp.l D0,D1 ; carry on D0 > D1 (D1 / D0 == 0)
bcc mq0
moveq.l #0,D0 ; D1 = D1, D0 = 0
move.l (sp)+,D2
rts
mq0 swap D0 ; denominator 16 bits?
tst.w D0
bne mq90
swap D0 ; yes, 32/16 -> 32, try divu
move.l D1,D2
divu D0,D2 ; D2 = rem|res
bvs md0 ; overflow, go slow
move.l D2,D1
clr.w D1
swap D1 ; D1 = rem
move.l D2,D0
swap D0
clr.w D0
swap D0 ; D0 = result
move.l (sp)+,D2
rts
mq90 swap D0
md0 move.l D3,-(sp)
move.l D4,-(sp)
moveq.l #0,D3
moveq.l #0,D4 ; result
move.l D0,D2 ; D2 = D0
md1 addq.l #1,D3
asl.l #1,D2
bcs md2
cmp.l D1,D2 ; loop while D2 <= D1
bls md1
md2 roxr.l #1,D2 ; overflow or went over, get prev D2
subq.l #1,D3
md3 sub.l D2,D1 ; and subtract
bset.l D3,D4 ; set bit in result (n)
md4 subq.l #1,D3
bcs md10
lsr.l #1,D2
cmp.l D1,D2 ; D2 - D1, bcs D1 > D2
bls md3 ; bls D1 >= D2
bra md4
md10
; result in D4, remainder in D1
move.l D4,D0
move.l (sp)+,D4
move.l (sp)+,D3
move.l (sp)+,D2
rts
END